﻿$(function () {
    $(".td-auditing").click(function () {
        var _this = $(this);
        var result = _this.attr("data-result");
        if (result == 1) {
            _this.attr("data-result", 0);
            _this.text("X");
        } else {
            _this.attr("data-result", 1);
            _this.text("O");
        }
        _this.parent().find(".td-auditing").each(function (index, el) {
            if ($(this).attr("data-result") == 0) {
                _this.parent().find(".td-auditing-result").text("不通过");
                return false;
            }
            if (index == _this.parent().find(".td-auditing").length - 1) {
                _this.parent().find(".td-auditing-result").text("通过");
            }
        });
    });

    $(".txt-score").change(function () {
        var val = $(this).val();
        var total = 0;
        $(this).parent().parent().find(".txt-score").each(function (index, el) {
            var itemVal = $(this).val();
            if (itemVal != '' && !isNaN(itemVal)) {
                total += parseFloat($(this).val());
            }
        });
        if (total > 0) {
            total = total.toFixed(2);
            $(this).parent().parent().find(".td-score-total").text(total);
        } else {
            $(this).parent().parent().find(".td-score-total").text("");
        }
    });

});
function SaveAuditing() {
    var postData = { ProjectId: ProjectId, AuditingType: AuditingType, SongPackageId: SongPackageId, ProjectAuditingList: [], AuditingPassRemark: $("#txtAuditingPassRemark").val() };
    var trList = $("#table_tbody").children("tr");

    for (var i = 0; i < trList.length; i++) {
        var SignUpAuditingList = {};
        var auditingList = [];
        var auditing;
        SignUpAuditingList.SignUpId = trList.eq(i).find("input[name='SignUpId']").val();

        trList.eq(i).find(".td-auditing").each(function (index, el) {
            auditing = {}
            auditing.DataId = $(this).attr("data-id");
            auditing.DataResult = $(this).attr("data-result");
            auditingList.push(auditing);
        });
        SignUpAuditingList.AuditingDataList = auditingList;
        postData.ProjectAuditingList.push(SignUpAuditingList);
    }
    //console.log(JSON.stringify(postData))
    $.ajax({
        url: '/ProjectAuditingRecord/SaveAuditingData/',
        data: postData,
        type: 'POST',
        success: function (result) {
            //console.log(JSON.stringify(result.Data));
            if (result.IsSuccess) {
                layer.msg(result.Message, {
                    icon: 1,
                    offset: 't',
                    time: 1500
                });
            } else {
                layer.msg(result.Message, {
                    icon: 2,
                    offset: 't',
                    time: 1500
                });
            }
        }
    });
}

function SaveScoreAuditing() {
    var postData = { ProjectId: ProjectId, AuditingType: AuditingType, SongPackageId: SongPackageId, ProjectAuditingList: []};
    var trList = $("#table_tbody").children("tr");

    for (var i = 0; i < trList.length; i++) {
        var SignUpAuditingList = {};
        var auditingList = [];
        var auditing;
        SignUpAuditingList.SignUpId = trList.eq(i).find("input[name='SignUpId']").val();

        trList.eq(i).find(".txt-score").each(function (index, el) {
            auditing = {}
            auditing.DataId = $(this).attr("data-id");
            auditing.AuditingScore = $(this).val();
            auditingList.push(auditing);
        });
        SignUpAuditingList.AuditingDataList = auditingList;
        postData.ProjectAuditingList.push(SignUpAuditingList);
    }
    //console.log(JSON.stringify(postData))
    $.ajax({
        url: '/ProjectAuditingRecord/SaveAuditingData/',
        data: postData,
        type: 'POST',
        success: function (result) {
            //console.log(JSON.stringify(result.Data));
            if (result.IsSuccess) {
                layer.msg(result.Message, {
                    icon: 1,
                    offset: 't',
                    time: 1500
                });
            } else {
                layer.msg(result.Message, {
                    icon: 2,
                    offset: 't',
                    time: 1500
                });
            }
        }
    });
}